<?php
include_once("fb.php");
include_once("cDAO.php");

class cCPDAO extends cDAO {
	
	function __construct($connection) {
		parent :: __construct($connection);
	}
	
	
	function getList(){
		$q = "select * from coupon limit 30";
		return $this->getSheet($q);	
	}
	
	function getRecommand(){
		$q = "select *,
				UNIX_TIMESTAMP(endDate)-UNIX_TIMESTAMP() tt,
				(select m5_gname from _good_code where m5_code=c.categoryCode) cc,
				(select CONCAT(NAME01,' ',NAME02) from _area_code where CODE01=c.area01 and CODE02=c.area02) aa		
				from coupon c where enddate > '$day' and UNIX_TIMESTAMP(endDate)-UNIX_TIMESTAMP()  > 0 order by salecnt  desc limit 5";
		return $this->getSheet($q);	
	}
	
	function getSaleCntList($name){
		$day = date("Y-m-d");		
		$arrName = explode(" ",$name);
		$name = array();
		foreach($arrName as $i=>$v){
			$name[] = " INSTR( sData, '$v' ) ";
		}
		$name = implode(" or ",$name);
		
		$q = "select *,
				UNIX_TIMESTAMP(endDate)-UNIX_TIMESTAMP() tt,
				(select m5_gname from _good_code where m5_code=c.categoryCode) cc,
				(select CONCAT(NAME01,' ',NAME02) from _area_code where CODE01=c.area01 and CODE02=c.area02) aa		
				from coupon c where enddate > '$day' and $name order by salecnt desc limit 100";
				
				fb($q);
		return $this->getSheet($q);	
	}
	
	//업체별 쿠폰 갯수 순위로 업체 리스트 가져오기
	function getCouponCntList($c=5){
		$day = date("Ymd");
		$q = "select id,mid,(select name from meta_site where id=mid) name,cnt from coupon_cnt c where instr( c.uDate,'$day')  order by c.cnt desc limit $c";
		
		return $this->getSheet($q);				
	}
}
?>
